package design_pattern;
//简单工厂
public class SimpleFactory {
    public static Product createProduct(String type) {
        if ("A".equals(type)) {
            return new A();
        } else {
            return new B();
        }
    }

    public static void main(String[] args) {
        Product product = SimpleFactory.createProduct("A");
        product.print();
    }
}
//工厂
abstract class AbstractFactory{
    public abstract Product createProduct();
}

class FactoryA extends AbstractFactory {

    @Override
    public Product createProduct() {
        return new A();
    }
}
abstract class Product {
    public abstract void print();
}

class A extends Product {

    @Override
    public void print() {
        System.out.println("产品A");
    }
}

class B extends Product {

    @Override
    public void print() {
        System.out.println("产品B");
    }
}